package ModelLayer;
import java.util.ArrayList;

/**
 * the DVDCollection class main surpose is to store a dvd collection. 
 * DVDCollection contains these methods:
 * GetDVD(find a dvd by its id)
 * addDVD(add a dvd to its collection)
 * deleteDVD(delete a dvd by its id)
 * ListDVD(list all dvds in the collection)
 * 
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVDCollection
{
    // instance variables - replace the example below with your own
    private ArrayList<DVD> dvds;

    /**
     * Constructor for objects of class DVDCollection
     */
    public DVDCollection()
    {
        // initialise instance variables
        dvds = new ArrayList<DVD>();
    }

    /**
     * Find the specific DVD by id
     */
    public DVD getDVD(int id)
    {
        for (DVD dvd : dvds) {
            if(dvd.getId() == id) {
                return dvd;
            }
        }
         return null;
    }
    
    /**
     * add DVD to DVDCollection
     */
    public void addDVD(DVD dvd)
    {
        dvds.add(dvd);
    }
    
    /**
     * Delete the specific DVD by id
     */
    public void deleteDVD(int id)
    {
        DVD dvd = getDVD(id);
        dvds.remove(dvd);
    }
    
    /**
     * List all dvds in the collection
     */
    public ArrayList listAllDvds()
    {
        return dvds;
    }
    
    public Copy getCopy(int serialNumber, int id)
    {
        DVD dvd = getDVD(id);
        if(dvd != null) {
            if(getDVD(id).getCopy(serialNumber).getSerialNumber() == serialNumber){
                return getDVD(id).getCopy(serialNumber);
            }
        }
    return null;
    }
    
    public ArrayList listAllCopies(int id)
    {
        return dvds.get(id).listAllCopies();
    }
}
